package com.cxyjy.common.util;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @Author: jony
 * @Date : 2024/11/12 21:58
 * @VERSION v1.0
 */
public class JPathUtil {
    /**
     * 返回字符串值为urlStr的URL
     * @param urlStr
     * @return
     * @throws MalformedURLException
     */
    public static URL getUrl(String urlStr) throws MalformedURLException {
        return new URL(urlStr);
    }

    /**
     * 根据用户的操作系统获取用户的Download文件夹
     * @return
     */
    public static String getUsersDownloadFolderPath(){
        String operateSystem = System.getProperty("os.name").toLowerCase();
        String usersFolderPath = System.getProperty("user.home");
        
        if(operateSystem.contains("win")){
            return usersFolderPath + "\\Downloads\\";
        } else if (operateSystem.contains("mac")) {
            return usersFolderPath + "/Downloads/";
        } else if (operateSystem.contains("nix") || operateSystem.contains("nux")){
            String xdgDownloadDir = System.getenv("XDG_DOWNLOAD_DIR")+"/";
            if (xdgDownloadDir != null) {
                return xdgDownloadDir;
            }
            return usersFolderPath + "/Downloads";
        } else {
            return null;
        }
    }

}
